#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e3+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL res=0;
void solve(string a,string b){
     for(LL i=0;i<a.size();i++){
        LL len=0;LL t=i;
        bool flag=0;
        for(LL j=0;j<b.size();j++){
            if(a[t]==b[j]||a[t]=='?'||b[j]=='?'){
                len++;
                if(j==b.size()-1||t==a.size()-1){
                    flag=1;
                    break;
                }
                t++;
            }else break;
        }
        if(flag) res=max(res,len);
    }
}
int main(void){
   	///cin.tie(0);std::ios::sync_with_stdio(false);
    string a,b;cin>>a>>b;
    solve(a,b);
    swap(a,b);
    solve(a,b);
    cout<<a.size()+b.size()-res<<"\n";
   	return 0;
}
